﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YWTSSys.DAL;
using YWTSSys.Model;
using YWTSSys.Library;
using System.Data;
namespace YWTSSys.BLL
{
    public class OMenuController : BaseController
    {
        #region 菜单操作相关
        /// <summary>
        /// 添加菜单
        /// </summary>
        /// <param name="obj">OMenu 对象</param>
        /// <param name="PermissionTags">对应的功能权限，以,隔开</param>
        /// <returns></returns>
        public static bool AddOMenu(OMenuInfo obj, string PermissionTags)
        {
            DC.Remove(AllOMenu);

            return OMenuDAL.AddOMenu(obj, PermissionTags);
        }
        /// <summary>
        /// 删除菜单项,将会删除所有已关联权限信息，包括已分配到用户的权限
        /// </summary>
        /// <param name="MenuId"></param>
        public static bool DeleteOMenuByMenuId(int MenuId)
        {
            DC.Remove(AllOMenu);

            return OMenuDAL.DeleteOMenuByMenuId(MenuId);
        }
        /// <summary>
        /// 菜单分页
        /// </summary>
        /// <param name="MenuName"></param>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <param name="Sort"></param>
        /// <param name="TotalCount"></param>
        public static DataTable GetOMenuPagination(string MenuName, int PageIndex, int PageSize, string Sort, ref int TotalCount)
        {
            return OMenuDAL.GetOMenuPagination(MenuName, PageIndex, PageSize, Sort, ref  TotalCount);
        }
        /// <summary>
        /// 修改菜单信息
        /// </summary>
        public static bool UpdateOMenuByMeunId(OMenuInfo obj)
        {
            DC.Remove(AllOMenu);

            return OMenuDAL.UpdateOMenuByMeunId(obj);
        }
        /// <summary>
        /// 获取菜单信息
        /// </summary>
        /// <param name="MenuId"></param>
        /// <returns></returns>
        public static OMenuInfo GetMenuByMenuId(int MenuId)
        { 
            //return 
            OMenuInfo obj=   CBO.FillObject<OMenuInfo>(OMenuDAL.GetOMenuByMenuId(MenuId));
            if (obj == null)
                return new OMenuInfo();
            return obj;
        }
        /// <summary>
        /// 根据ParentId获取其下所有的菜单信息
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public static List<OMenuInfo> GetAllParentMenu(int parentId)
        {
            List<OMenuInfo> obj = CBO.FillCollection<OMenuInfo>(OMenuDAL.GetAllParentMenu(parentId));
            if (obj.Count <= 0)
                return new List<OMenuInfo>();
            return obj;
        }
        /// <summary>
        /// 获取所有的菜单
        /// </summary>
        /// <returns></returns>
        public static DataTable GetAllOMenu()
        {
            DataTable dt = DC.Get<DataTable>(AllOMenu1);
            if (dt == null)
            {
                dt = OMenuDAL.GetAllOMenu();
                DC.Add(AllOMenu1, dt);
            }
            return dt;
        }

        public static List<OMenuInfo> GetAllOMenu2()
        {
            List<OMenuInfo> dt = DC.Get<List<OMenuInfo>>(AllOMenu2);
            if (dt == null)
            {
                dt =CBO.FillCollection<OMenuInfo>( OMenuDAL.GetAllOMenu2());
                DC.Add(AllOMenu2, dt);
            }
            return dt;
        }

        #endregion

        #region 菜单功能权限操作相关
        /// <summary>
        /// 单个页面权限添加
        /// </summary>
        /// <param name="MenuId"></param>
        /// <param name="PermissionTag"></param>
        public static bool AddOMenuPermission(int MenuId, string PermissionTag)
        {
            return OMenuDAL.AddOMenuPermission(MenuId, PermissionTag);
        }
        /// <summary>
        /// 在添加菜单时批量添加权限信息
        /// </summary>
        /// <param name="MenuId"></param>
        /// <param name="PermissionTags"></param>
        public static bool AddOMenuPermissionByMenu(int MenuId, string PermissionTags)
        {
            return OMenuDAL.AddOMenuPermissionByMenu(MenuId, PermissionTags);
        }
        /// <summary>
        /// 删除菜单功能权限,将会删除已分配出去的权限
        /// </summary>
        /// <param name="FunId"></param>
        public static bool DeleteOMenuPermissionByTag(int MenuId, string Tag)
        {
            return OMenuDAL.DeleteOMenuPermissionByTag(MenuId, Tag);
        }

        /// <summary>
        /// 获取菜单对应的权限信息
        /// </summary>
        /// <param name="MenuId"></param>
        /// <returns></returns>
        public static List<OMenuPermissionInfo> GetOMenuPermissionByMenuId(int MenuId)
        {
            //return 
            List<OMenuPermissionInfo> obj = CBO.FillCollection<OMenuPermissionInfo>(OMenuDAL.GetOMenuPermissionByMenuId(MenuId));
            if (obj.Count<=0)
                return new List<OMenuPermissionInfo>();
            return obj;
        }

        public static DataTable GetAllOMenuPermission()
        {
            return OMenuDAL.GetAllOMenuPermission();
        }
        #endregion
    }
}
